package org.javaboy.fmall.entity;

import lombok.extern.slf4j.Slf4j;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @ClassName ValidatedWorkOverTime
 * @Description
 * @Author find me
 * @Date 2020/8/2 0002 17:25
 * @Version 1.0
 */
@Slf4j
public class ValidatedWorkOverTime implements ConstraintValidator<WorkOverTime,Object> {

    private Integer max;

    private WorkOverTime workOverTime;

    @Override
    public void initialize(WorkOverTime constraintAnnotation) {
        this.max = constraintAnnotation.max();
        this.workOverTime = constraintAnnotation;
    }

    @Override
    public boolean isValid(Object integer, ConstraintValidatorContext constraintValidatorContext) {
        Integer overWorkTime = Integer.MAX_VALUE;
        if(integer instanceof Integer){
            overWorkTime = (Integer) integer;
        }else{
            try {
                overWorkTime = Integer.parseInt(integer.toString());
            }catch (Exception e){
                log.error(e.toString(),e);
                if(e instanceof NumberFormatException){

                }
            }
        }
        return max>overWorkTime;
    }
}